import Taro from "@tarojs/taro";

export const DEFAULT_VALUE = {
  ARRAY: "[]",
  OBJECT: "{}",
  STRING: ""
};

export const localStorageFactory = params => {
  const { defaultValue, key, raw = false } = params;
  const setItem = value => {
    const data = value || defaultValue;
    Taro.setStorageSync(key, data);
  };
  const removeItem = () => {
    Taro.removeStorageSync(key);
  };
  const getItem = () => {
    const data = raw ? defaultValue : Taro.getStorageSync(key) || defaultValue;
    return data;
  };
  return {
    getItem,
    setItem,
    removeItem
  };
};
